/*
 *         Copyright (c) KUBOTA Corporation and HUDSON SOFT,
 *                  1994, 1995 All Rights Reserved
 *
 *  This software comprises unpublished confidential information of
 *  KUBOTA Corp. and HUDSON SOFT. It may not be used, copied or made 
 *  available to anyone, except in accordance with the license under
 *  which it is furnished.
 */
static char SccsId[] = "@(#)look2.c	1.8	9/19/95";
#include <farl.h>
#include <agl.h>
unsigned int cube[] = {
#include "cubestp.h"
};

object	o, o2[6];
fix1015	v[3];

void main()
{
     register long	i;
     register int	j;
     Material	mt1 = {0x1000, 0x7fff, 0x4fff,};

     FX73init();
     FX73_cmap_i6c3();
     AGLInit();

     FarlSetPEClearColorReg(0x807);
     FarlSetPEICMaskReg(FARL_ICMASK_I6C3);
     FarlSetTEControlReg(FARL_TE_LTEN|FARL_TE_ICM /*|FARL_TE_SPEN*/|FARL_TE_BCE);
     FarlValidateSwap();

     AGLSetLightVector(AGL_LIGHT0, FarlGetSin1015(3600-450),
		       0x0,
		       FarlGetSin1015(3600-450));
     AGLSetMaterial(&mt1, 1);

     o.geometryTop    = cube;
     o.geometryLength = sizeof(cube)/sizeof(int);
     o.material = &mt1;

     for (i = 0; i < 6; i++) {
	  o2[i].geometryTop    = cube;
	  o2[i].geometryLength = sizeof(cube)/sizeof(int);
	  o2[i].material = NULL;
     }

     for (i = 0; ; i+= 30) {
	  for (j = 0; j < 6; j++) AGLResetObj(&o2[j]);
	  AGLRotateObjZ(&o2[0], (i*3) % 3600);
	  AGLRotateObjX(&o2[1], (i*3) % 3600);
	  AGLRotateObjZ(&o2[2], (i*3) % 3600);
	  AGLRotateObjX(&o2[3], (i*3) % 3600);
	  AGLRotateObjY(&o2[4], (i*3) % 3600);
	  AGLRotateObjY(&o2[5], (i*3) % 3600);

	  AGLTranslateObj(&o2[0], 0x0, 0xff80, 0x0);
	  AGLTranslateObj(&o2[1], 0x80, 0x0, 0x0);
	  AGLTranslateObj(&o2[2], 0x0, 0x80, 0x0);
	  AGLTranslateObj(&o2[3], 0xff80, 0x0, 0x0);
	  AGLTranslateObj(&o2[4], 0x0, 0x0, 0x80);
	  AGLTranslateObj(&o2[5], 0x0, 0x0, 0xff80);
	  
	  v[0] = FarlGetSin1015(i%3600);
	  v[1] = FarlGetSin1015((i/5)%3600);
	  v[2] = FarlGetCos1015(i%3600);
	  FarlNormalizeVector(v);
	  AGLResetObj(&o);
	  
	  AGLRotateObjZ(&o, i%3600);
	  AGLTranslateObj(&o, CONV1015TO187(v[0]),
			  CONV1015TO187(v[1]),
			  CONV1015TO187(v[2]));
	  
	  AGLResetCamera();
	  AGLTranslateCamera(FarlGetSin187(i%3600)<<2,
			     0x60,
			     FarlGetCos187(i%3600)<<2);
	  AGLLookAtCamera( CONV1015TO187(v[0]), CONV1015TO187(v[1]),
			  CONV1015TO187(v[2]), 0x0, 0x7fff, 0x0);
	  AGLZoomCamera(0x80, 0x80, 0x20);
	  AGLPerspectiveCamera(0xff80);
	  
	  AGLFixPutObj(&o);
	  for (j = 0; j < 6; j++) AGLFixPutObj(&o2[j]);
	  AGLShot();
     }
     return;
}
